<?php
		
	/* SVN FILE: $Id: uploads.remove.php 8 2011-03-13 08:32:38Z michele.andreoletti@gmail.com $ */
	
	/**
	 * Project Name : arcadia
	 *
	 * @author $Author: michele.andreoletti@gmail.com $
	 * @version $Revision: 8 $
	 * @lastrevision $Date: 2011-03-13 08:32:38 +0000 (Sun, 13 Mar 2011) $
	 * @filesource $URL: http://arcadia.googlecode.com/svn/trunk/include/uploads.remove.php $
	 */
	
	date_default_timezone_set('Europe/Rome');
	
	if(isset($_GET['sAPP']) && !empty($_GET['sAPP'])) {
		$sAPP = $_GET['sAPP'];	

	} else {
		require_once "./const.inc.php";
		require_once "./functions.php";
		// require_once "./auth.inc.php";
		require_once "./conn.inc.php";
		
		fnUpdateLog('APP NOT DEFINED', 0, '', 'E');
		echo fnJsonOutput(fnCurrentScript(), '', '', 888);
		die();
	
	}

	require_once "../$sAPP/include/const.inc.php";
	require_once "../$sAPP/include/functions.php";
	require_once "./auth.inc.php";
	require_once "./conn.inc.php";
	
	fnGetValueFromGET(array('sAction','iUpload','iView','sViewItemLink'));

	fnViewConst($sViewItemLink);
		
	$sScript = fnCurrentScript();
	
	$iAccessLvl = fnViewAccessLvl($iView, $aTABLE, $aTABLE_SECURITY_CHECK);
	
	$iFieldAccessLvl = fnFieldAccessLvl($iAccessLvl, $sViewItemLink, $iTabUploads);

	if (is_allowed('view', $iFieldAccessLvl)) {
		
		if (isset($sAction) && $sAction == 'Remove')  {
		
			if (is_allowed('delete', $iFieldAccessLvl)) {
				
				$sQuery = "SELECT * FROM `uploads` WHERE `id`='$iUpload' AND `iView`='$iView'";
				$rResult = custom_mysql_query($sQuery);
				if (mysql_num_rows($rResult) == 1) {
					$aRow = mysql_fetch_array($rResult);
					$sQuery = "DELETE FROM `uploads`, `uploads_bin` USING `uploads`
						INNER JOIN `uploads_bin` WHERE `uploads`.`id` = `uploads_bin`.`iUpload`
						AND `uploads`.`id`='$iUpload'";
					$rResult = custom_mysql_query($sQuery);
					fnUpdateLog("FILE DELETED [".$aRow['sName']."]", $iView, $sViewSelectFrom, 'I');
					$sOutput = fnJsonOutput($sScript, $sAction, '', 0);
					
				} else {
					fnUpdateLog("FILE NOT FOUND", $iView, $sViewSelectFrom, 'E');
					$sOutput = fnJsonOutput($sScript, $sAction, '', 333);

				}
				
			} else {
				fnUpdateLog("LOW RIGTHS", $iView, $sViewSelectFrom, 'S');
				$sOutput = fnJsonOutput($sScript, $sAction, '', 999);
		
			}
				
		} else {
			fnUpdateLog('ACTION NOT VALID', $iView, $sViewSelectFrom, 'E');
			$sOutput = fnJsonOutput($sScript, $sAction, '', 101);
			
		}
		
	} else {
		fnUpdateLog("LOW RIGTHS", $iView, $sViewSelectFrom, 'S');
		$sOutput = fnJsonOutput($sScript, $sAction, '', 999);

	}
	
	echo $sOutput;
	die();

?>